<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <!--<el-form-item label="用户名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="名字" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名字"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学号" prop="arcNum">
        <el-input
          v-model="queryParams.arcNum"
          placeholder="请输入学号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="personId">
        <el-input
          v-model="queryParams.personId"
          placeholder="请输入身份证"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入年龄"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择用户性别" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!--<el-form-item label="出生日期" prop="birthday">
        <el-date-picker clearable size="small"
          v-model="queryParams.birthday"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择出生日期">
        </el-date-picker>
      </el-form-item>-->
      <!--<el-form-item label="电话" prop="telephone">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <!--<el-form-item label="籍贯" prop="nativePlace">
        <el-input
          v-model="queryParams.nativePlace"
          placeholder="请输入籍贯"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="民族" prop="national">
        <el-input
          v-model="queryParams.national"
          placeholder="请输入民族"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="家庭住址" prop="familyPlace">
        <el-input
          v-model="queryParams.familyPlace"
          placeholder="请输入家庭住址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="专业" prop="professional">
        <el-input
          v-model="queryParams.professional"
          placeholder="请输入专业"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入学时间" prop="admissionTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.admissionTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="入学时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="毕业时间" prop="graduationTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.graduationTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="毕业时间">
        </el-date-picker>
      </el-form-item>
      <!--<el-form-item label="入学考号" prop="candidateNumber">
        <el-input
          v-model="queryParams.candidateNumber"
          placeholder="请输入入学考号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业证书" prop="graduationCard">
        <el-input
          v-model="queryParams.graduationCard"
          placeholder="请输入毕业证书"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生证号" prop="degreeCertificate">
        <el-input
          v-model="queryParams.degreeCertificate"
          placeholder="请输入学生证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['archives:archivessystem:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['archives:archivessystem:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['archives:archivessystem:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['archives:archivessystem:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="archivessystemList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--<el-table-column label="id" align="center" prop="id" />
      <el-table-column label="用户名" align="center" prop="userName" />-->
      <el-table-column label="学号" align="center" prop="arcNum"/>
      <el-table-column label="名字" align="center" prop="name"/>
      <el-table-column label="身份证" align="center" prop="personId"/>
      <!-- <el-table-column label="年龄" align="center" prop="age" />-->
      <el-table-column label="用户性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="出生日期" align="center" prop="birthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电话" align="center" prop="telephone"/>
      <!--<el-table-column label="籍贯" align="center" prop="nativePlace" />-->
      <el-table-column label="民族" align="center" prop="national"/>
      <!--<el-table-column label="家庭住址" align="center" prop="familyPlace" />-->
      <el-table-column label="专业" align="center" prop="professional"/>
      <el-table-column label="入学时间" align="center" prop="admissionTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.admissionTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="毕业时间" align="center" prop="graduationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.graduationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="入学考号" align="center" prop="candidateNumber" />-->
      <el-table-column label="毕业证书" align="center" prop="graduationCard"/>
      <el-table-column label="学生证号" align="center" prop="degreeCertificate"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['archives:archivessystem:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['archives:archivessystem:remove']"
          >删除
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-zoom-in"
            @click="handleDetails(scope.row)"
            v-hasPermi="['archives:archivessystem:query']"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--个人信息详情对话框-->
    <el-dialog :title="title" :visible.sync="dialogVisible" width="800px" append-to-body>
      <el-descriptions class="margin-top" :column="3" :size="size" border>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            学 号
          </template>
          {{form.arcNum}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user-solid"></i>
            用户名
          </template>
          {{form.userName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-s-custom"></i>
            姓 名
          </template>
          {{form.name}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-postcard"></i>
            身份证
          </template>
          {{form.personId}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-d-caret"></i>
            年 龄
          </template>
          {{form.age}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-coordinate"></i>
            性 别
          </template>
          {{form.sex}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-mobile-phone"></i>
            电话号码
          </template>
          {{form.telephone}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-time"></i>
            出生日期
          </template>
          {{form.birthday}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-s-check"></i>
            民 族
          </template>
          <el-tag size="small">{{form.national}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-house"></i>
            专 业
          </template>
          <el-tag size="small">{{form.professional}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-time"></i>
            入学时间
          </template>
          {{form.admissionTime}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-time"></i>
            毕业时间
          </template>
          {{form.graduationTime}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-collection-tag"></i>
            入学考号
          </template>
          {{form.candidateNumber}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-collection-tag"></i>
            毕业证书
          </template>
          {{form.graduationCard}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-collection-tag"></i>
            学生证书号
          </template>
          {{form.degreeCertificate}}
        </el-descriptions-item>
      </el-descriptions>
      <el-descriptions class="margin-top" :column="3" :size="size" border>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-position"></i>
            家庭住址
          </template>
          {{form.familyPlace}}
        </el-descriptions-item>
      </el-descriptions>
      <el-descriptions class="margin-top" :column="3" :size="size" border>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-map-location"></i>
            户口籍贯
          </template>
          {{form.nativePlace}}
        </el-descriptions-item>
      </el-descriptions>
      <div slot="footer" class="dialog-footer">
        <!--<el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">返 回</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改档案管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" inline="true">
        <!--el-form-item label="用户名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户名" />
        </el-form-item>-->
        <el-form-item label="名字" prop="name">
          <el-input v-model="form.name" placeholder="请输入名字"/>
        </el-form-item>
        <!--<el-form-item label="学号" prop="arcNum">
          <el-input v-model="form.arcNum" placeholder="请输入学号" />
        </el-form-item>-->
        <el-form-item label="身份证" prop="personId">
          <el-input v-model="form.personId" placeholder="请输入身份证"/>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄"/>
        </el-form-item>
        <el-form-item label="用户性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择用户性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" prop="birthday">
          <el-date-picker clearable size="small"
                          v-model="form.birthday"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <div></div>
        <el-form-item label="电话" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入电话"/>
        </el-form-item>
        <el-form-item label="籍贯" prop="nativePlace">
          <el-input v-model="form.nativePlace" placeholder="请输入籍贯"/>
        </el-form-item>
        <el-form-item label="民族" prop="national">
          <el-input v-model="form.national" placeholder="请输入民族"/>
        </el-form-item>
        <el-form-item label="家庭住址" prop="familyPlace">
          <el-input v-model="form.familyPlace" placeholder="请输入家庭住址"/>
        </el-form-item>
        <!-- <el-form-item label="专业" prop="professional">
           <el-input v-model="form.professional" placeholder="请输入专业" />
         </el-form-item>-->
        <el-form-item label="入学考号" prop="candidateNumber">
          <el-input v-model="form.candidateNumber" placeholder="请输入入学考号"/>
        </el-form-item>
        <el-form-item label="毕业证书" prop="graduationCard">
          <el-input v-model="form.graduationCard" placeholder="请输入毕业证书"/>
        </el-form-item>
        <el-form-item label="学生证号" prop="degreeCertificate">
          <el-input v-model="form.degreeCertificate" placeholder="请输入学生证号"/>
        </el-form-item>
        <div></div>
        <el-form-item label="入学时间" prop="admissionTime">
          <el-date-picker clearable size="small"
                          v-model="form.admissionTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择入学时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="毕业时间" prop="graduationTime">
          <el-date-picker clearable size="small"
                          v-model="form.graduationTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择毕业时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listArchivessystem,
    getArchivessystem,
    delArchivessystem,
    addArchivessystem,
    updateArchivessystem
  } from "@/api/archives/archivessystem";

  export default {
    name: "Archivessystem",
    dicts: ['sys_user_sex'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 档案管理表格数据
        archivessystemList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 是否显示详情框
        dialogVisible: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userName: null,
          name: null,
          arcNum: null,
          personId: null,
          age: null,
          sex: null,
          birthday: null,
          telephone: null,
          nativePlace: null,
          national: null,
          familyPlace: null,
          professional: null,
          admissionTime: null,
          graduationTime: null,
          candidateNumber: null,
          graduationCard: null,
          degreeCertificate: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询档案管理列表 */
      getList() {
        this.loading = true;
        listArchivessystem(this.queryParams).then(response => {
          this.archivessystemList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.dialogVisible = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          userName: null,
          name: null,
          arcNum: null,
          personId: null,
          age: null,
          sex: null,
          birthday: null,
          telephone: null,
          nativePlace: null,
          national: null,
          familyPlace: null,
          professional: null,
          admissionTime: null,
          graduationTime: null,
          candidateNumber: null,
          graduationCard: null,
          degreeCertificate: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加档案管理";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getArchivessystem(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改档案管理";
        });
      },
      handleDetails(row) {
        this.reset();
        const id = row.id || this.ids
        getArchivessystem(id).then(response => {
          this.form = response.data;
          let tempSex = this.form.sex;
          if (tempSex === 0) {
            this.form.sex = '女';
          } else {
            this.form.sex = '男';
          }
          this.dialogVisible = true;
          this.disabled = true;
          this.open = false;
          this.title = "查询学生个人信息";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateArchivessystem(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addArchivessystem(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除档案管理编号为"' + ids + '"的数据项？').then(function () {
          return delArchivessystem(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('archives/archivessystem/export', {
          ...this.queryParams
        }, `archivessystem_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
